Skip to content

Pitfall: GCC 6.5 puts memory indirect operands on the wrong stack slot after a call - #59

Merged
WDrijver merged 1 commit into
mainfrom
pitfall/gcc-double-indirect-stack-slot
Nov 17, 2026
Merged

WDrijver merged 1 commit into
mainfrom
pitfall/gcc-double-indirect-stack-slot

Conversation

@WDrijver

Copy link
Copy Markdown
Contributor

What

A new toolchain pitfall, toolchain/pitfalls/gcc-double-indirect-stack-slot.md.

Since double-indirect-fix.patch was dropped (ApolloCrossDev PR #15, 2026-11-04), GCC-6.50-Dev emits memory indirect operands on -m68080. When a pointer argument gets no register, reload addresses it as ([N,sp]) with the stack offset of function entry. Between a call's argument pushes and the pop, that is another argument's slot:

    jsr     (a0)
    add.l   d2,([56,sp])     ; meant *out_ctr += n; 56(sp) is cinfo's slot here
    lea     (20,sp),sp
  • -m68020 and -m68060 don't use the mode.
  • -fno-double-indirect gives correct code: move.l (76,sp),a0.
  • The bbb pass is not involved.

Found during

The ApolloOS R10 port. MultiView crashed on every JPEG, because libjpeg's sep_upsample in jfif.library never advanced the scanline and bumped cinfo->err instead.

A whole-build scan of 7662 C files found 23437 memory indirect operands, 2236 of them sp-based in 676 files. With -fno-double-indirect there are none, and the rebuilt tree shows the JPEG on the V4.

Reported to ApolloCrossDev as issue WDrijver/ApolloCrossDev#27, with the reproduction.

Knowledge base files relied on

  • toolchain/compiler-variants.md (double-indirect-fix.patch history)
  • core/pitfalls/double-memory-indirect.md (the mode is slow on the 080)
  • toolchain/pitfalls/gcc-bbb-shift-wrong-code.md (format)

Local checks: check_frontmatter, check_links and check_saga_addresses pass.

🤖 Generated with Claude Code

GCC-6.50-Dev on -m68080 addresses a pointer argument without a register
as ([N,sp]) with the entry offset, also while a call's arguments are
pushed. Found in libjpeg (ApolloOS R10); -fno-double-indirect avoids it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@WDrijver
WDrijver requested a review from TuKo1982 as a code owner November 17, 2026 09:30
@WDrijver
WDrijver merged commit 6d33b6d into main Nov 17, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant